
package editor.ui
{
	import com.bit101.components.Label;
	import com.bit101.components.PushButton;
	import com.bit101.components.Window;
	import com.zero.framework.interfaces.INotification;
	import com.zero.framework.interfaces.INotifyResponder;
	import com.zero.framework.observer.Facade;
	
	import editor.Notification.M2VNotification;
	import editor.Notification.V2MNotification;
	import editor.common.AppFacade;
	import editor.common.CursorManager;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.ui.MouseCursor;
	
	
	/**
	 * @author 缺硒
	 */
	public class GatesInfoWindow extends Window implements INotifyResponder
	{
		private var _outGateBtn:PushButton;
		private var _inGateBtn:PushButton;
		private var _outGateLabel:Label;
		private var _inGateLabel:Label;
		private var _inX:Label;
		private var _inY:Label;
		private var _outX:Label;
		private var _outY:Label;
		
		//进城点是否已增加
		private var _isInOK:Boolean = false;
		//出城点是否已增加
		private var _isOutOK:Boolean = false;
		private var _inPoint:Point = new Point();
		private var _outPoint:Point = new Point();
		
		// 构造函数
		public function GatesInfoWindow(parent:DisplayObjectContainer, xpos:Number=0, ypos:Number=0, title:String="传送门")
		{
			AppFacade.getIntance().registerResponder(this);
			
			super(parent, xpos, ypos, title);
			setSize(120, 195);
			
			
			

			
			_outGateLabel 	= new Label(this, 10, 10, "出城点:");
			_outX 			= new Label(this, 10, 30, "X:");
			_outY 			= new Label(this, 60, 30, "Y:");
			_outGateBtn 	= new PushButton(this, 10, 55, "增加", onOutBtn);
			
			_inGateLabel 	= new Label(this, 10, 85, "进城点:");
			_inX 			= new Label(this, 10, 105, "X:");
			_inY 			= new Label(this, 60, 105, "Y:");
			_inGateBtn 		= new PushButton(this, 10, 130, "增加", onInBtn);
			

		}
		
		public function get notificationList():Array
		{
			return [
				M2VNotification.UPDATE_GATES_INFO,
				M2VNotification.ADD_IN_OK,
				M2VNotification.ADD_OUT_OK
			];
		}
		
		public function notifyHandler(notification:INotification):void
		{
			var data:Object = notification.getBody();
			switch(notification.getName())
			{
				case M2VNotification.UPDATE_GATES_INFO:
					_inPoint.x = data.inX;
					_inPoint.y = data.inY;
					
					_outPoint.x = data.outX;
					_outPoint.y = data.outY;
					
					_inX.text = "X: " + data.inX.toString();
					_inY.text = "Y: " + data.inY.toString();
					
					_outX.text = "X: " + data.outX.toString();
					_outY.text = "Y: " + data.outY.toString();
					break;
				case M2VNotification.ADD_IN_OK:
					_isInOK = true;
					_inGateBtn.label = "定位";
					break;
				case M2VNotification.ADD_OUT_OK:
					_isOutOK = true;
					_outGateBtn.label = "定位";
					break;
				default:
					new Error(Facade.ERROR_NOTIFICATION_NOT_SEEN);
					break;
			}
		}
		
		private function onOutBtn(evt:Event):void
		{
			if(_isOutOK == false)
			{
				CursorManager.getInstance().state = CursorManager.STATE_ADD_OUT;
			}
			else
			{
				AppFacade.getIntance().sendNotification(V2MNotification.SET_MAP_VIEW,
					{
						vx:_outPoint.x,
						vy:_outPoint.y
					});
			}
		}
		
		private function onInBtn(evt:Event):void
		{
			if(_isInOK == false)
			{
				CursorManager.getInstance().state = CursorManager.STATE_ADD_IN;
			}
			else
			{
				AppFacade.getIntance().sendNotification(V2MNotification.SET_MAP_VIEW,
					{
						vx:_inPoint.x,
						vy:_inPoint.y
					});
			}
		}
		//
		
	}
}